package com.maizhi.dao.impl;

import java.io.Serializable;

import com.maizhi.util.PropertiesUtil;

/**
 * 分页对象.包含当前页数据及分页信息如总记录数.
 *
 */
public class Page implements java.io.Serializable {
	
	private static final long serialVersionUID = -5624189033006412710L;

	PropertiesUtil ppu ;
    /**
     * 页码
     */
    private int pageNumber = 1;

    /**
     * 每页多少行
     */
    private int perPageRow = 1;

    /**
     * 页码
     */
    private int totlePageNumber = 1;

    /**
     * 记录数
     */
    private int count = 1;

    /**
     * 页码
     */
    private int firstReslut = 1;

    /**
     * constructor Page documentation comment
     */
    public Page() 
    {
        ppu = new PropertiesUtil("classPath:config.Properties");
        this.firstReslut=Integer.parseInt(ppu.getByKey("page.firstReslut")==null?"1":ppu.getByKey("page.firstReslut"));
        this.perPageRow=Integer.parseInt(ppu.getByKey("page.perPageRow")==null?"10":ppu.getByKey("page.perPageRow"));
        this.totlePageNumber=0;
        this.count=Integer.parseInt(ppu.getByKey("page.count")==null?"0":ppu.getByKey("page.count"));
        this.pageNumber=Integer.parseInt(ppu.getByKey("page.pageNumber")==null?"1":ppu.getByKey("page.pageNumber"));
    }

    /**
     * constructor Page documentation comment
     *
     * @param pageNumber
     * @param perPageRow
     * @param totlePageNumber
     * @param count
     * @param firstReslut
     */
    public Page(int pageNumber, int perPageRow, int totlePageNumber,
    		int count, int firstReslut) 
    {
        super();
        this.pageNumber = pageNumber;
        this.perPageRow = perPageRow;
        this.totlePageNumber = totlePageNumber;
        this.count = count;
        this.firstReslut = firstReslut;
    }

    /**
     * @return long:Returns the count.
     */
    public final int getCount() 
    {
        return this.count;
    }

    /**
     * @param count:The
     *            count to set.
     */
    public final void setCount(int count) 
    {
        this.count = count;
        this.setTotlePageNumber((count%this.perPageRow>0)?(count/this.perPageRow+1):(count/this.perPageRow));
    }

    /**
     * @return int:Returns the firstReslut.
     */
    public final int getFirstReslut() 
    {
        this.firstReslut = (pageNumber - 1) * perPageRow;
        return this.firstReslut;
    }

    /**
     * @param firstReslut:The
     *            firstReslut to set.
     */
    public final void setFirstReslut(int firstReslut) 
    {
        this.firstReslut = firstReslut;
    }

    /**
     * @return int:Returns the pageNumber.
     */
    public final int getPageNumber() 
    {
    	return this.pageNumber;
    }

    /**
     * @param pageNumber:The
     *            pageNumber to set.
     */
    public final void setPageNumber(int pageNumber) 
    {
    	if(pageNumber<1){
    		this.pageNumber=1;
    	}else if(pageNumber>this.totlePageNumber && this.totlePageNumber>0){
    		this.pageNumber=this.totlePageNumber;
    	}else{
    		this.pageNumber=pageNumber;
    	}
    }

    /**
     * @return int:Returns the perPageRow.
     */
    public final int getPerPageRow() 
    {
        return this.perPageRow;
    }

    /**
     * @param perPageRow:The
     *            perPageRow to set.
     */
    public final void setPerPageRow(int perPageRow) 
    {
        this.perPageRow = perPageRow;
    }

    /**
     * @return int:Returns the totlePageNumber.
     */
    public final int getTotlePageNumber()
    {
        return this.totlePageNumber<1?1:this.totlePageNumber;
    }

    /**
     * @param totlePageNumber:The
     *            totlePageNumber to set.
     */
    public final void setTotlePageNumber(int totlePageNumber) 
    {
        this.totlePageNumber = totlePageNumber<1?1:totlePageNumber;
        if(this.pageNumber>this.totlePageNumber){
        	setPageNumber(this.totlePageNumber);
        }
    }

}
